/* Original Author:  Dominick O'Dierno
 * Date: 2007   odiernod@gmail.com     --Originally intended for use with DOMercury:  http://www.odierno.com/domercury
 * Description: Provides actions for an System Window Item
 * 
 * --CHANGELOG--
 * 
 * */
using System;
using System.Collections.Generic;
using System.Text;
using ManagedWinapi;
using DOMercury.Interfaces;
using DOMercury.Items;

namespace DOMercury.Actions
{
    public class SWShow : IAction
    {
        #region IAction Members

        public string ActionType
        {
            get { return "Show"; }
        }

        public string Description
        {
            get { return "Brings to Front the selected Window"; }
        }

        public string ParamDescription
        {
            get { return "Unused"; }
        }

        public string ParameterType
        {
            get { return "CommandLine"; }
        }

        public bool Perform(IItem item, object specialParams)
        {
            Win32.ShowWindow(((SystemWindowItem)(item)).Hwnd, (int)Win32.WindowShowLParam.ShowMaximized);
            return Win32.ShowWindow(((SystemWindowItem)(item)).Hwnd, (int)Win32.WindowShowLParam.Restore);
        }

        #endregion
    }
    public class SWMaximize : IAction
    {
        #region IAction Members

        public string ActionType
        {
            get { return "Maximize"; }
        }

        public string Description
        {
            get { return "Maximizes the selected Window"; }
        }

        public string ParamDescription
        {
            get { return "Unused"; }
        }

        public string ParameterType
        {
            get { return "CommandLine"; }
        }

        public bool Perform(IItem item, object specialParams)
        {
            return Win32.ShowWindow(((SystemWindowItem)(item)).Hwnd, (int)Win32.WindowShowLParam.ShowMaximized);
        }

        #endregion
    }

    public class SWMinimize : IAction
    {
        #region IAction Members

        public string ActionType
        {
            get { return "Minimize"; }
        }

        public string Description
        {
            get { return "Minimizes the selected Window"; }
        }

        public string ParamDescription
        {
            get { return "Unused"; }
        }

        public string ParameterType
        {
            get { return "CommandLine"; }
        }

        public bool Perform(IItem item, object specialParams)
        {
            return Win32.ShowWindow(((SystemWindowItem)(item)).Hwnd, (int)Win32.WindowShowLParam.Minimize);
        }

        #endregion
    }

    public class SWClose : IAction
    {
        #region IAction Members

        public string ActionType
        {
            get { return "Close"; }
        }

        public string Description
        {
            get { return "Closes selected Window"; }
        }

        public string ParamDescription
        {
            get { return "Unused"; }
        }

        public string ParameterType
        {
            get { return "CommandLine"; }
        }

        public bool Perform(IItem item, object specialParams)
        {
            SystemWindowItem swi = ((SystemWindowItem)(item));
            if (((swi.ClassName == "IEFrame") || (swi.ClassName == "CabinetWClass")) && (System.Environment.OSVersion.Version.Major == 5))
            {
                swi.Process.Kill();
            }
            else
            {
                Win32.SendMessage(swi.Hwnd, (int)Win32.Msgs.WM_CLOSE, 0, 0);
            }
            
            return true;
        }

        #endregion
    }

    public class SWRestore : IAction
    {
        #region IAction Members

        public string ActionType
        {
            get { return "Restore"; }
        }

        public string Description
        {
            get { return "Restores the selected Window to its default size"; }
        }

        public string ParamDescription
        {
            get { return "Unused"; }
        }

        public string ParameterType
        {
            get { return "Hwnd"; }
        }

        public bool Perform(IItem item, object specialParams)
        {
            return Win32.ShowWindow(((SystemWindowItem)(item)).Hwnd, (int)Win32.WindowShowLParam.Restore);
        }

        #endregion
    }
}
